<script>
	import api from '@/utils/api.js';
	import util from '@/utils/util.js';
	export default {
		onLaunch: function() {
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			varsion: '1.0.0',
			token: null,
			// baseApi: 'http://127.0.0.1:9999/outdoor/',
			// baseApi: 'http://192.168.100.102:9999/outdoor/',
			baseApi: 'https://hsapi.meijingnet.cn/hsApi/',
			userInfo: null,
			categoryInfo: null,
			indexInfo: null,
			commonList: [],
			excludeValue: null,
			excludeBrand: null,
		},
		methods: {
			customerService(that) {
				that.showMingpian = true;
				// #ifdef MP-WEIXIN
				// wx.openCustomerServiceChat({
				// 	extInfo: {
				// 		url: 'https://work.weixin.qq.com/kfid/kfcee668fca90eed8e7',
				// 	},
				// 	corpId: 'wwa0b87a02d11887c3',
				// 	complete(e){
				// 		console.log(e)
				// 	},
				// })
				// #endif
			},
			async userInfo() {
				if (this.globalData.userInfo) {
					return this.globalData.userInfo;
				}
				let {
					data = null
				} = await api.user_info();
				if (data) {
					this.globalData.userInfo = data;
				}
				return data;
			},
			async getCategoryInfo() {
				let excludeValue = await this.getExcludeValue();
				if (this.globalData.categoryInfo) {
					return this.globalData.categoryInfo;
				}
				let {
					result = null
				} = await api.category_info(excludeValue);
				if (result) {
					this.globalData.categoryInfo = result;
				}
				return result;
			},
			async getIndexInfo() {
				let excludeValue = await this.getExcludeValue();
				if (this.globalData.indexInfo) {
					return this.globalData.indexInfo;
				}
				let {
					result = null
				} = await api.index_product_info(excludeValue);
				if (result) {
					this.globalData.indexInfo = result;
				}
				return result;
			},
			async getCommonList() {
				if (this.globalData.commonList.length > 0) {
					return this.globalData.commonList;
				}
				let {
					result = []
				} = await api.comment_list();
				if (result?.length > 0) {
					for (let i of result) {
						i.labelStr = i.labelStr || '';
						i.labelList = i.labelStr.split(',');

						i.amt = i.amount.toLocaleString();

						i.height = 0;
					}
					this.globalData.commonList = result;
				}
				return result;
			},
			async getExcludeValue() {
				if (this.globalData.excludeValue) {
					return this.globalData.excludeValue;
				}
				let result;
				// #ifdef MP-WEIXIN
				let e = await api.dict_json_value('app_config', 'wxxcx');
				result = e.result || {};
				// #endif
				// #ifdef MP-ALIPAY
				let e = await api.dict_json_value('app_config', 'alixcx');
				result = e.result || {};
				// #endif
				this.excludeValue = result || {};
				return result;
			},
			async getExcludeBrand() {
				if (this.globalData.excludeBrand) {
					return this.globalData.excludeBrand;
				}
				let result;
				// #ifdef MP-WEIXIN
				let e = await api.dict_value('app_config', 'wxxcx_exclude_brand');
				result = e.result || '';
				// #endif
				// #ifdef MP-ALIPAY
				let e = await api.dict_value('app_config', 'alixcx_exclude_brand');
				result = e.result || '';
				// #endif
				this.excludeBrand = JSON.parse(result);
				return this.excludeBrand;
			},
		}
	}
</script>

<style lang="scss">
	@import '@/css/app.css';
</style>